package cn.star.jots.filmSort.service.impl;

import cn.star.jots.filmSort.mapper.FilmSortMapper;
import cn.star.jots.filmSort.pojo.dto.FilmSortSaveParam;
import cn.star.jots.filmSort.pojo.entity.FilmSort;
import cn.star.jots.filmSort.pojo.vo.FilmSortVO;
import cn.star.jots.filmSort.service.FilmSortService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class FilmSortServiceImpl implements FilmSortService {

    @Autowired
    FilmSortMapper filmSortMapper;

    @Override
    public List<FilmSortVO> selectFirst(Integer sort) {
        log.debug("查询电影,参数:{}", sort);
        return filmSortMapper.selectFirst(sort);
    }

    @Override
    public List<FilmSortVO> selectNotIn(Integer sort) {
        log.debug("查询电影,参数:{}", sort);
        return filmSortMapper.selectNotIn(sort);
    }

    @Override
    public List<FilmSortVO> selectAll() {
        log.info("查询电影");
        return filmSortMapper.selectAll();
    }

    @Override
    public void save(FilmSortSaveParam filmSortSaveParam) {
        log.debug("保存电影,参数:{}", filmSortSaveParam);
        FilmSort filmSort = new FilmSort();
        BeanUtils.copyProperties(filmSortSaveParam, filmSort);
        if (filmSort.getId() == null){
            filmSort.setCreateTime(new Date());
            filmSortMapper.insert(filmSort);
        } else {
            filmSort.setUpdateTime(new Date());
            filmSortMapper.update(filmSort);
        }
    }

    @Override
    public  List<FilmSortVO> selectById(Long id) {
        log.debug("查询电影,参数:{}", id);
        return filmSortMapper.selectById(id);
    }

    @Override
    public void delete(Long id) {
        log.debug("删除电影,参数:{}", id);
        filmSortMapper.delete(id);
    }
}
